package com.zziq.cloudpicturebank.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zziq.cloudpicturebank.api.aliyunAi.model.CreateOutPaintingTaskResponse;
import com.zziq.cloudpicturebank.model.dto.picture.*;
import com.zziq.cloudpicturebank.model.entity.Picture;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zziq.cloudpicturebank.model.entity.User;
import com.zziq.cloudpicturebank.model.vo.picture.PictureDownloadResponse;
import com.zziq.cloudpicturebank.model.vo.picture.PictureVO;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import java.util.Map;

/**
 * @author Mr·张
 * @description 针对表【picture(图片)】的数据库操作Service
 * @createDate 2025-02-21 14:53:56
 */
public interface PictureService extends IService<Picture> {
    /**
     * 上传图片
     *
     * @param inputSourse
     * @param pictureUploadRequest
     * @param loginUser
     * @return
     */
    PictureVO uploadPicture(Object inputSourse,
                            PictureUploadRequest pictureUploadRequest,
                            User loginUser);


    boolean updatePicture(PictureUpdateRequest pictureUpdateRequest, User loginUser);

    /**
     * 封装查询条件
     *
     * @param pictureQueryRequest
     * @return
     */

    QueryWrapper<Picture> getQueryWrapper(PictureQueryRequest pictureQueryRequest);

    /**
     * 实体类转vo(单条)
     *
     * @param picture
     * @param request
     * @return
     */
    PictureVO getPictureVO(Picture picture, HttpServletRequest request);

    /**
     * 实体类转vo(多条)
     *
     * @param picturePage
     * @param request
     * @return
     */
    Page<PictureVO> getPictureVOPage(Page<Picture> picturePage, HttpServletRequest request);

    /**
     * 校验图片
     *
     * @param picture
     */
    void validPicture(Picture picture);

    /**
     * 图片审核
     *
     * @param pictureReviewRequest
     * @param loginUser
     */
    void doPictureReview(PictureReviewRequest pictureReviewRequest, User loginUser);

    /**
     * 填充审核状态信息
     *
     * @param picture
     * @param loginUser
     */
    void fillReviewParams(Picture picture, User loginUser);

    /**
     * 批量抓取和创建图片
     *
     * @param pictureUploadByBatchRequest
     * @param loginUser
     * @return 成功创建的图片数
     */
    Integer uploadPictureByBatch(
            PictureUploadByBatchRequest pictureUploadByBatchRequest,
            User loginUser
    );

    /**
     * 分页获取封装图片列表（带缓存）
     *
     * @param pictureQueryRequest
     * @param request
     * @return
     */
    Page<PictureVO> listPictureVOByPageWithCache(PictureQueryRequest pictureQueryRequest, HttpServletRequest request);

    /**
     * 清理云存储图片-异步
     *
     * @param oldPicture
     */
    void clearPictureFile(Picture oldPicture);

    /**
     * 批量清理云存储图片-异步
     *
     * @param oldPictureList
     */
    void clearPictureFileBatch(List<Picture> oldPictureList);

    /**
     * 校验 用户操作图片的权限
     *
     * @param loginUser
     * @param picture
     */
    void checkPictureAuth(User loginUser, Picture picture);

//    void checkPictureAuth2(User loginUser, Picture picture);

    /**
     * 删除图片
     * @param pictureId
     * @param loginUser
     */
    void deletePicture(long pictureId, User loginUser);

    /**
     * 批量删除图片 (删除空间时使用)
     * @param spaceId 空间id
     * @param loginUser 登录用户
     */
    void deletePictureBatch(User loginUser,Long spaceId);

    /**
     * 用户编辑图片
     * @param pictureEditRequest
     * @param loginUser
     */
    void editPicture(PictureEditRequest pictureEditRequest, User loginUser);

    /**
     * 根据颜色搜索图片
     * @param spaceId
     * @param picColor
     * @param loginUser
     *
     * @return
     */
    List<PictureVO> searchPictureByColor(Long spaceId, String picColor, User loginUser);

    /**
     * 批量编辑图片
     * @param pictureEditByBatchRequest
     * @param loginUser
     */
    @Transactional(rollbackFor = Exception.class)
    void editPictureByBatch(PictureEditByBatchRequest pictureEditByBatchRequest, User loginUser);


    CreateOutPaintingTaskResponse createPictureOutPaintingTask(CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest, User loginUser);

    /**
     * 下载图片
     * @param picture
     * @param loginUser
     */
    void downloadPicture(Picture picture, User loginUser, boolean isCompress, HttpServletResponse response) throws IOException;
}
